function [profit, lr] = profit_ftn(D_input, cost_rs, cost_ml,...
    beta_f, T1, B1_f, B2_f, weight_claim_cost, use_cost_weight)
%% get data
p1 = D_input.p1;
p2 = D_input.p2;
s1_predicted = D_input.s1_predicted;
s2_mkt = D_input.s2_mkt;
claims2 = D_input.claims2;
pr_s = D_input.pr_s;
major = D_input.major;

%% profits
profit1 = B1_f*p1.*s1_predicted;

if use_cost_weight==0
    profit2_k = (p2-claims2).*s2_mkt - cost_rs;
else
    profit2_k = p2.*s2_mkt - weight_claim_cost - cost_rs;
end

profit2 = (beta_f^T1)*B2_f*sum(pr_s.*profit2_k,2);

% N.ist x 1
profit = profit1 + profit2 - cost_ml;

%% loss ratio = EPDV claims/EPDV premiums
epdv_claims = (beta_f^T1)*B2_f*sum(pr_s.*claims2.*s2_mkt,2);
epdv_prems = B1_f*p1.*s1_predicted + (beta_f^T1)*B2_f*sum(pr_s.*p2.*s2_mkt,2);

% N.ist x 1
lr = epdv_claims./epdv_prems;

